#include "stdafx.h"
#include "../Resource.h"
#include "App.h"
#include "../ui/Frame.h"
#include "../win32/FrameWin32.h"
namespace App{
	FrameWin32 frame_;
	WithProperties properties;

	void SetProperty(wstring propertyName, boost::any value){
		properties.SetProperty(propertyName, value);
	}
	void Init(HINSTANCE hInstance, LPTSTR lpCmdLine, int nCmdShow){
		if(!frame_.Create(0, 0, 500, 400)){
			Exit();
			return;
		}
		::UpdateWindow(frame_.GetWnd());
		::ShowWindow(frame_.GetWnd(), SW_SHOW);
		BIND_MSG_FUN_LAST(frame_.GetWnd(), WM_DESTROY, &OnFrameDestroy);
		/*for(int i=1; i< __argc; ++i){
			Log<<L"OpenFile:"<<__wargv[i]<<endl;
			GetEditor()->OpenFile(__wargv[i]);
		}*/
	}
	MSGPROC(OnFrameDestroy){
		Rect r;
		GetWindowRect(frame_.GetWnd(), &r);
		
		return 0;
	}
	FrameWin32* GetMainFrame(){
		return &frame_;
	}
	
	void Exit(int code){
		PostQuitMessage(code);
	}
	int MainLoop(){
		MSG msg = {0};
		//HACCEL  hAccelTable = Config::CreateAccel(); //LoadAccelerators(instance_, MAKEINTRESOURCE(IDC_MYEDITOR));
		while (GetMessage(&msg, NULL, 0, 0))
		{
			//if (!TranslateAccelerator(GetMainFrame()->GetWnd(), hAccelTable, &msg))
			{
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		return (int) msg.wParam;
	}
};
